﻿#include"head.h"

//为仓库申请空间
void AllGoodListInit(ptask* goodlist)
{
	(*goodlist) = (ptask)malloc(sizeof(struct task_str));
	if(goodlist == NULL)
	{
		perror("good init size failed");
		exit(0);
	}
}

//将商品送入仓库
void StoreCommodityInit(ptask commodity)
{	
	g_attribute attr[] = {
		/*0*/{"1112223330000","洗发露",2,"kg",19.8,"2019.07.01",6,"月"},
			 {"1112223330010","牙膏",0.5,"L" ,19.8,"2019.07.01",12,"月"},
			 {"1112223330020","香水",0.2,"kg",100.0,"2016.02.08",6,"月"},
			 {"1112223330030","笤帚",8,"kg",100.0,"2016.02.12",12,"月"},
			 {"1112223330040","保温杯",1,"个",100.0,"2016.05.08",12,"月"},
			 {"1112223330050","脸盆",1,"kg",100.0,"2017.02.08",12,"月"},
		/*6*/{"1112223330060","花盆",2,"kg",100.0,"2014.02.02",12,"月"},
	};
	commodity->allgoodlist.index = 6;
	
	memcpy(commodity->allgoodlist.attr,attr,sizeof(attr));
	
	//printf("%s,%f,%d\n",commodity->allgoodlist.attr[3].commodityname,commodity->allgoodlist.attr[6].price,commodity->allgoodlist.index);
	
}

void GoodEnterUpInit(ptask good)
{
	struct good_enterup* p1 = &(good->goodlogin);
	bzero(p1,sizeof(struct good_enterup));
	
}

void GoodCancelInit(ptask good)
{
	struct good_cancel* p1 = &(good->goodcode);
	bzero(p1,sizeof(struct good_cancel));
	
}

ptask InitOperatorFunc()
{
	task *good;
	/*1.1初始化仓库*/
	AllGoodListInit(&good);//为仓库申请空间
	StoreCommodityInit(good);//将商品送入仓库
	
	/*1.2初始化已购的商品列表，使用双向链表存储已经选中的商品信息*/
	DLinkListInit(good);
	CreatSingleLinkInit(good);
	
	/*1.3初始化商品登记*/
	GoodEnterUpInit(good);
	
	/*1.4初始化取消购买结构体*/
	GoodCancelInit(good);
	
	return good;
}
